<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>lesson 19</title>
    <script src="../dist/vue.js"></script>
</head>
<body>
<div id="root"></div>
</body>
<script>
    // 动态组件: 根据数据的变化，结合 compoent 这个标签，来随时动态切换组件的现实
    // 异步组件: 是异步执行某些组件的逻辑，这叫做异步组件

    const app = Vue.createApp({
        template: `
      <div>
        <common-item ref="sssss"/>
        <async-common-item />
      </div>
    `,
        mounted(){
            console.log(this.$refs.sssss.say())
        }
    });

    app.component('common-item', {
        methods:{
            say(){
                alert(1)
            }
        },
        template: `<div>hello world</div>`
    });

    app.component('async-common-item', Vue.defineAsyncComponent(() => {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve({
                    template: `<div>this is an async component</div>`
                })
            }, 4000)
        })
    }))

    const vm = app.mount('#root');
</script>
</html>
